<?php

namespace App\Console\Commands\OpenShop;

use App\Enums\OpenShop\InvestmentPromotion\SignOrderEnum;
use App\Models\OpenShop\InvestmentPromotion\OpenShopOrganizationManageModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSignOrderPermissionAnchorModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopSiteMissionModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserBaseInfoModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserContractModel;
use App\Models\OpenShop\InvestmentPromotion\OpenShopUserExtContractModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationModel;
use App\Models\OpenShop\StartBusiness\OpenShopStartBusinessModel;
use App\Service\Guanyuan\CurlService;
use App\Service\OpenShop\Feishu\OrganizationManageService;
use App\Service\OpenShop\Feishu\ShopManualService;
use App\Service\OpenShop\OrderService;
use App\Support\OrganizationManageFsRobotSendSupport;
use Illuminate\Console\Command;

class OpenShopResgin extends Command
{
    protected $signature   = 'open_shop:resign {shopCode}';
    protected $description = '开店订单合同状态恢复';


    public function handle()
    {
        $shopCode = (int)$this->argument('shopCode');

        $signOrder = OpenShopSignOrderModel::query()
                                           ->with('baseInfoRel')
                                           ->where('shopCode', $shopCode)
                                           ->first();

        if (empty($signOrder)) {
            $this->info('查无此订单 结束操作');
            return;
        }

        // 查找作废的合同
        $contract = OpenShopUserContractModel::query()
                                             ->where('categoryName', 'like', '%解%')
                                             ->where('orderNo', $signOrder->orderNo)
                                             ->first();

        $signOrder->status         = 1;
        $signOrder->contractStatus = 1;
        $signOrder->dissolveStatus = 0;
        $signOrder->save();

        if ($contract) {
            $contract->isDeleted = 0;
            $contract->save();
        }

        $this->info('订单还原成功');
    }


}
